import 'package:json_annotation/json_annotation.dart';

part 'product.g.dart';

@JsonSerializable()
class ProductModel {
  /// 图片
  late String imgUrl;

  /// 名称
  late String name;

  /// 月售
  late int? monthSale;

  /// 库存
  late int inventory;

  /// 标签
  late List<String> tags;

  /// 介绍
  @JsonKey(includeFromJson: true, required: false)
  String? introduce;

  /// 归类
  ProductClassifyEnum? classify;

  /// 标注
  ProductMarkEnum? mark;

  /// 实价
  int? actualPrice;

  /// 售价
  int? salePrice;

  /// 临时变量
  bool isSelected;

  /// true = 套餐, false = 单品
  bool meal;

  ProductModel(
      {required this.imgUrl,
      required this.name,
      required this.inventory,
      this.monthSale,
      this.tags = const [],
      this.introduce,
      this.classify,
      this.mark,
      this.actualPrice,
      this.salePrice,
      this.isSelected = false,
        this.meal = false
      });

  factory ProductModel.fromJson(Map<String, dynamic> json) => _$ProductModelFromJson(json);

  Map<String, dynamic> toJson() => _$ProductModelToJson(this);

  @override
  String toString() {
    return toJson().toString();
  }
}

@JsonSerializable(includeIfNull: false)
class ProductClassifyModel {
  int id;

  /// 名称
  String name;

  /// 分类描述
  String describe;

  bool available;

  ProductClassifyModel(
      {this.id = 0, required this.name, required this.describe, this.available = true});

  factory ProductClassifyModel.fromJson(Map<String, dynamic> json) =>
      _$ProductClassifyModelFromJson(json);

  Map<String, dynamic> toJson() => _$ProductClassifyModelToJson(this);

  @override
  String toString() {
    return toJson().toString();
  }
}

enum ProductClassifyEnum {
  /// 新品
  news(1, '新品', '#63b54b', '#FFFFFF'),

  /// 招牌
  signboard(2, '招牌', '#ff6e53', '#FFFFFF');

  final int value;
  final String text;
  final String backgroundColor;
  final String textColor;

  const ProductClassifyEnum(this.value, this.text, this.backgroundColor, this.textColor);
}

enum ProductMarkEnum {
  /// 即将过期
  expire(
    1,
    '即将过期',
    '#00000080',
    '#FFFFFF',
  ),

  /// 审核中
  review(
    2,
    '审核中',
    '#ff000070',
    '#FFFFFF',
  ),

  /// 未开售
  noSale(
    3,
    '未开售',
    '#00000080',
    '#FFFFFF',
  ),

  /// 审核失败
  auditFailure(
    4,
    '审核失败',
    '#ff000070',
    '#FFFFFF',
  ),

  /// 已过期
  overtTime(
    5,
    '已过期',
    '#00000080',
    '#FFFFFF',
  ),

  ///已售罄
  soldOut(
    6,
    '已售罄',
    '#00000080',
    '#FFFFFF',
  );

  final int value;
  final String text;
  final String backgroundColor;
  final String textColor;

  const ProductMarkEnum(this.value, this.text, this.backgroundColor, this.textColor);
}
